import request from '@/utils/request'

export function addEvent(data) {
  return request({
    url: '/v1/events/add',
    method: 'post',
    data: {
      group: data.group,
      projectId: data.projectId,
      moduleId: data.moduleId,
      taskId: data.taskId,
      respPerson: data.respPerson,
      devPerson: data.devPersion,
      testPerson: data.testPerson,
      peType: data.peType,
      describe: data.describe,
      preRepair: data.preRepair,
      preOnline: data.preOnline,
      tempCode: data.upload.tempCode,
      remarks: data.remarks,
      attachments: data.uploadFileList
    }
  })
}

export function editEvent(data) {
  return request({
    url: '/v1/events/edit',
    method: 'put',
    data: {
      peId: data.peId,
      group: data.group,
      projectId: data.projectId,
      moduleId: data.moduleId,
      taskId: data.taskId,
      respPerson: data.respPerson,
      devPerson: data.devPersion,
      testPerson: data.testPerson,
      peType: data.peType,
      describe: data.describe,
      preRepair: data.preRepair,
      preOnline: data.preOnline,
      tempCode: data.upload.tempCode,
      remarks: data.remarks,
      attachments: data.uploadFileList
    }
  })
}

export function findByPage(data, pageSize, pageNum) {
  return request({
    url: '/v1/events/findByPage',
    method: 'get',
    params: {
      group: data.group,
      projectId: data.projectId,
      devPerson: data.devPerson,
      lv1ModuleId: data.lv1ModuleId,
      lv2ModuleId: data.lv2ModuleId,
      recordBegin: data.recordBegin,
      recordEnd: data.recordEnd,
      peStatus: data.peStatus,
      devStatus: data.devStatus,
      pageSize: pageSize,
      pageNum: pageNum
    }
  })
}

export function exportExcel(data) {
  return request({
    url: '/v1/events/export',
    method: 'post',
    data: {
      group: data.group,
      projectId: data.projectId,
      devPerson: data.devPerson,
      lv1ModuleId: data.lv1ModuleId,
      lv2ModuleId: data.lv2ModuleId,
      recordBegin: data.recordBegin,
      recordEnd: data.recordEnd,
      peStatus: data.peStatus,
      devStatus: data.devStatus
    },
    responseType: 'blob'
  })
}

export function remove(id) {
  return request({
    url: '/v1/events/remove/' + id,
    method: 'delete'
  })
}

export function changeDevPerson(id, userId) {
  return request({
    url: '/v1/events/changeDevPerson/' + id,
    method: 'put',
    data: {
      devPerson: userId
    }
  })
}

export function changeTestPerson(id, userId) {
  return request({
    url: '/v1/events/changeTestPerson/' + id,
    method: 'put',
    data: {
      testPerson: userId
    }
  })
}

export function eventStart(id) {
  return request({
    url: '/v1/events/start/' + id,
    method: 'put'
  })
}

export function eventTest(id) {
  return request({
    url: '/v1/events/test/' + id,
    method: 'put'
  })
}

export function eventReStart(id) {
  return request({
    url: '/v1/events/restart/' + id,
    method: 'put'
  })
}

export function eventSubmit(id, codeRepository) {
  return request({
    url: '/v1/events/submit/' + id,
    method: 'put',
    data: {
      codeRepository: codeRepository
    }
  })
}

export function eventFinish(id) {
  return request({
    url: '/v1/events/finish/' + id,
    method: 'put'
  })
}

export function eventClose(id) {
  return request({
    url: '/v1/events/close/' + id,
    method: 'put'
  })
}
